Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push: add custom messenger (BC) #17211

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Push: add custom messenger (BC) #17211

wants to merge 4 commits into from

Conversation

andig
Copy link
Member

@andig andig commented Nov 12, 2024

Fix #17148 by adding custom messenger. Custom messenger uses encoding to combine title and msg into a single value to send to plugin. Valid encodings are json, csv and tsv. If encoding is omitted only the message is transferred.

BC: removes script messenger. This is replaced by:

- type: custom
  source: script
  encoding: tsv
  cmdline: foo -bar

@andig andig added the enhancement New feature or request label Nov 12, 2024
Copy link
Collaborator

@GrimmiMeloni GrimmiMeloni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we still need the cmdline execution parts from the former script implementation?

push/push.go Outdated Show resolved Hide resolved
push/push.go Show resolved Hide resolved
Co-authored-by: Michael Heß <[email protected]>
@andig
Copy link
Member Author

andig commented Nov 14, 2024

Bleibt die Frage, ob wir das mergen wollen?

@GrimmiMeloni
Copy link
Collaborator

Regarding my previous comment

Don't we still need the cmdline execution parts from the former script implementation?

I now connected the dots, of the registry looking up the provider (factory) via the source field in the config. Not that obvious, took me a moment to grasp.

Bleibt die Frage, ob wir das mergen wollen?

Yes, I think so.

@rhuss
Copy link
Contributor

rhuss commented Nov 15, 2024

Nice reuse of the existing plugin interface :) Does this mean that you can reuse any of the plugins as service endpoint for events ? (mqtt, modbus, http, script, ... all plugins that allow write access).

switch m.encoding {
case "json":
b, _ := json.Marshal(struct {
Title string `json:"title"`
Copy link
Contributor

@rhuss rhuss Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title string `json:"title"`
Title string `json:"title,omitempty"`

I would check if the title is empty or not defined in the config, and omit the title when empty.
This is a common use case for machine-readable payloads like JSON.

You could also allow the msg to be specified in JSON directly, to not impose your custom schema { msg: ..., title: ... } to the user. See #17278 for a proposal.

})
res = string(b)
case "csv":
res = title + "," + msg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too simplistic, especially when title and message can contain commas (to tabs for tsv). Do we really need csv and tsv ? I can't see any good use case that can not be solved with a stronger typed representation (like json).

res = title + "," + msg
case "tsv":
res = title + "\t" + msg
case "title":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type does not "fit" into the list: json, csv, tsv are formats (so kind of an encoding), "title" and "message" (the default) are more filters.

Wdyt to restrict encoding to "json" and "string" (or "raw") and have some second options as to whether to include the title or not ? (usually if you only use a single service endpoint and you don't need the title, you just don't define it in events: ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for messaging via mqtt
4 participants